package kaka.rpc.ServiceClasses
{
	import kaka.rpc.IInvokeResponder;
	
	import flash.events.EventDispatcher;
	
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import mx.rpc.remoting.mxml.RemoteObject;
	import kaka.rpc.AsyncResponder;
	import kaka.rpc.IInvoker;
	import kaka.rpc.IInvokeResponder;
	public class RemoteObjectInvoker extends EventDispatcher implements IInvoker
	{
		private var ro:RemoteObject;
		private var _defaultHandler:Function;
		public function RemoteObjectInvoker()
		{
		}
		
		public function invoker(dest:String,method:String, args:Array,defaultHandler:Function):IInvokeResponder
		{
			ro=new RemoteObject(dest);
			this._defaultHandler=defaultHandler;
			var oper:AbstractOperation=ro.getOperation(method);
			var token:AsyncToken=oper.send.apply(oper,args);
			return new AsyncResponder(token,_defaultHandler);
		}
	}
}